//==============================================================================
// FASTAFile.hh
//-----------------------------------------------------------------------------
// Handles specifics of parsing a FASTA format file. 
//
//------------------------------------------------------------------------------
// $Id: FASTAFile.hh,v 1.2 2000/02/01 23:42:20 kdurbin Exp kdurbin $
//------------------------------------------------------------------------------
// $Log: FASTAFile.hh,v $
// Revision 1.2  2000/02/01 23:42:20  kdurbin
// *** empty log message ***
//
// Revision 1.1  2000/02/01 22:16:01  kdurbin
// Initial revision
//
//==============================================================================
//.......1.........2.........3.........4.........5.........6.........7.........8
//

#include "LocalSTL.hh"
#include "Sequence.hh"
#include "ParseUtils.hh"

#ifndef _FASTA_FILE
#define _FASTA_FILE


//------------------------------------------------------------------------------
// * FASTAFile
//------------------------------------------------------------------------------
// Encapsulates methods to read and write FASTA format files.  Perhaps a bit 
// too little to be a class in and of itself, but I like separating file parsing
// functionality from the data abstraction class (here Sequence or SequenceQuality),
// which I think should be kept ignorant of where the data comes from. 
//
// Since reading files is common, and often the files can be extreemly large, 
// several variations on the methods have been implemented to experiment with 
// speed enhancements.   
//
// TODO: This class sorely needs functionality to read a FASTAFile a little bit 
// at a time.  Perhaps the cleanest way to do this is to inherit from iostream. 
//
class FASTAFile{
public:

  ~FASTAFile(){};
  FASTAFile(){mExpectedSize = 5000;
              mSeqLineSize = 50;
              mQualLineSize = 25;};

  bool   Read(istream &fin,Sequence &Seq);

  bool   Append(istream &fin,SequenceVector &SeqVec);

  bool   Read(istream &fin,SequenceVector &SeqVec);
  bool   Read(string FileName,Sequence &Seq);
  bool   Read0(string FileName,Sequence &Seq);
  bool   Read(string FileName,SequenceVector &SeqVec);
  bool   Read0(string FileName,SequenceVector &SeqVec);

  // KJD This should simply be Read and let function overloading decide which one. 
  bool   ReadQual(string FileName,SequenceQualityVector &QualVec);
  bool   ReadQual0(string FileName,SequenceQualityVector &QualVec);
  bool   ReadQual(string FileName,SequenceQuality &Qual);

  bool   Read(string FileName,SequenceQuality &Qual){
	 return(ReadQual(FileName,Qual));
  }

  bool   Read(string FileName,SequenceQualityVector &Qual){
	 return(ReadQual(FileName,Qual));
  }


  bool   ReadQual(istream&fin,SequenceQualityVector &QualVec);
  bool   ReadQualX(istream&fin,SequenceQualityVector &QualVec);

  void   Write(ostream &fout,Sequence &Seq);
  void   Write(ostream &fout,SequenceVector &SeqVec);
  void   Write(string FileName,Sequence &Seq);
  void   Write(string FileName,SequenceVector &SeqVec);
  void   WriteQual(string FileName,SequenceQuality &Qual);
  void   WriteQual(string FileName,SequenceQualityVector &QualVec);

  void   Write(string FileName,SequenceQuality &Qual){
	 WriteQual(FileName,Qual);
  }

  void   Write(string FileName,SequenceQualityVector &Qual){
	 WriteQual(FileName,Qual);
  }

  void   WriteQual(ostream &fout,SequenceQuality &Qual);
  void   WriteQual(ostream &fout,SequenceQualityVector &Qual);

  void   SetExpectedSize(long seqSize);

  
  bool GetNextRead(istream &fin,char *buffer,int bufSize,Sequence &Seq);

  long mExpectedSize;  // Expected size of file to read in. 

  // Size of a line when writing out quality or EXP. 
  int mSeqLineSize;
  int mQualLineSize;

protected:

};

// Create an alias since I always want to type this..
typedef FASTAFile FAFile;


#endif
